package mysql

import (
	"fmt"
	"gorm.io/gorm"
)

type Fitness struct {
	gorm.Model
	Title       string `gorm:"type:varchar(50);not null;comment:'课程的标题'" json:"title"`
	Duration    string `gorm:"type:varchar(100);not null;comment:'课程视频时长'" json:"duration"`
	Author      string `gorm:"type:varchar(30);not null;comment:'视频作者'" json:"author"`
	Kilocalorie int64  `gorm:"type:int;not null;comment:'运动的热量'" json:"kilocalorie"`
	Browse      int64  `gorm:"type:int;not null;comment:'浏览量'" json:"browse"`
}

func (f *Fitness) Create() error {
	return DB.Debug().Create(&f).Error

}

func (f *Fitness) List() (list []*Fitness, err error) {
	err = DB.Debug().Find(&list).Error
	if err != nil {
		fmt.Println("查询失败")
		return nil, err
	}
	return
}

func (f *Fitness) GetFithess() (list []*Fitness, err error) {
	err = DB.Debug().Order("browse asc").Find(&list).Limit(10).Error
	if err != nil {
		fmt.Println("推荐失败")
		return nil, err
	}
	return
}
